const compareImages = require("resemblejs/compareImages");
const fs = require("mz/fs");

async function screenCompare() {
  const options = {
    output: {
      errorColor: {
        red: 255,
        green: 0,
        blue: 255
      },
      errorType: "movement",
      transparency: 0.3,
      largeImageThreshold: 1200,
      useCrossOrigin: false,
      outputDiff: true
    },
    scaleToSameSize: true,
    ignore: "antialiasing"
  };

  const data = await compareImages(
    await fs.readFile("catalins-origin.png"),
    await fs.readFile("catalins.png"),
    options
  );
  console.log(data);
  if(data.rawMisMatchPercentage !== 0) {
    await fs.writeFile("./output.png", data.getBuffer());
    return true;
  } else {
    return false;
  }
}

module.exports = screenCompare;